package com.party.core.service.crowdfund.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.crowdfund.ProjectDetailCountReadDao;
import com.party.core.dao.write.crowdfund.ProjectDetailCountWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.crowdfund.ProjectDetailCount;
import com.party.core.model.crowdfund.ProjectDetailCountInput;
import com.party.core.model.crowdfund.ProjectDetailCountOutput;
import com.party.core.service.crowdfund.IProjectDetailCountService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: yangshoukun
 * @Date: 2018/6/12 15:38
 */
@Service
public class ProjectDetailCountService implements IProjectDetailCountService {

    @Autowired
    private ProjectDetailCountReadDao projectDetailCountReadDao;

    @Autowired
    private ProjectDetailCountWriteDao projectDetailCountWriteDao;

    @Override
    public String insert(ProjectDetailCount projectDetailCount) {
        BaseModel.preInsert(projectDetailCount);

        boolean result = projectDetailCountWriteDao.insert(projectDetailCount);
        if (result){
            return projectDetailCount.getId();
        }
        return null;
    }

    @Override
    public boolean update(ProjectDetailCount projectDetailCount) {
        return projectDetailCountWriteDao.update(projectDetailCount);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return projectDetailCountWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return projectDetailCountWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return projectDetailCountWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return projectDetailCountWriteDao.batchDelete(ids);
    }

    @Override
    public ProjectDetailCount get(String id) {
        return projectDetailCountReadDao.get(id);
    }

    @Override
    public List<ProjectDetailCount> listPage(ProjectDetailCount projectDetailCount, Page page) {
        return projectDetailCountReadDao.listPage(projectDetailCount, page);
    }

    @Override
    public List<ProjectDetailCount> list(ProjectDetailCount projectDetailCount) {
        return listPage(projectDetailCount, null);
    }

    @Override
    public List<ProjectDetailCount> batchList(Set<String> ids, ProjectDetailCount projectDetailCount, Page page) {
        return null;
    }

    @Override
    public ProjectDetailCountOutput getCountByEvent(ProjectDetailCountInput input) {
        return projectDetailCountReadDao.getCountByEvent(input);
    }

    @Override
    public ProjectDetailCount findByProjectIdDate(String projectId, Date createDate) {
        return projectDetailCountReadDao.findByProjectIdDate(projectId, createDate);
    }

    @Override
    public void deleteByProjectId(String projectId) {
        projectDetailCountWriteDao.deleteByProjectId(projectId);
    }
}
